package com.example.second_home_work

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.Spinner
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    private lateinit var button1: Button
    private lateinit var button2: Button
    private lateinit var spinner: Spinner
    private lateinit var textView2: TextView
    private lateinit var scrollView: ScrollView
    private lateinit var linearLayout: LinearLayout
    private val expert = ProgramExpert()
    private var clickCount = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        button1 = findViewById(R.id.button1)
        button2 = findViewById(R.id.button2)
        spinner = findViewById(R.id.spinner)
        textView2 = findViewById(R.id.textView2)
        scrollView = findViewById(R.id.scrollView)
        linearLayout = findViewById(R.id.linearLayout)

        button1.setOnClickListener {
            clickCount++
            val newTextView = TextView(this).apply {
                text = getString(R.string.new_textview, clickCount)
                textSize = 20f
            }
            linearLayout.addView(newTextView)
            scrollView.post {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN)
            }
        }

        button2.setOnClickListener {
            val selectedFeature = spinner.selectedItem.toString()
            textView2.text = expert.getLanguage(selectedFeature)
        }
    }
}